Note: There are often multiple ways to answer each question.
Use the seq()
function to create a vector that starts with 1, ends with 5, and has length 26. (Use ?seq
to look up the documentation for the seq()
function.)
Load the mtcars
dataset using data(mtcars)
. How many rows and columns are there in this dataset? What are the column names?
What is the highest mpg
value?
Which car has the highest mpg
value?
How many of each value are there in the cyl
column?
How many NA
s are there in the cyl
column?
Extract the rows of the dataset for which hp > 110
.
Extract the rows of the dataset for which am
has value 1 and carb
has value 4.
Note that the car names are not actually a column in the data frame! Create a new column in the dataframe, “name”, which holds the car name. (Hint: The rownames()
function will be useful.)
Sort the dataframe in ascending order of car name. (Hint: The order()
function may be useful.)